home *** CD-ROM | disk | FTP | other *** search
/ Greenhouse Effect Detection Expriment / NASA Greenhouse Effect Detection Expriment 1992 - Disc 2.iso / software / dos / cdf22pc / src / lib / cdfinfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-09  |  5.6 KB  |  257 lines

  1. /******************************************************************************
  2. *
  3. *  NSSDC/CDF             Maintain CDF information for OBSOLETE interface.
  4. *
  5. *  Version 1.2, 10-Feb-92, ST Systems (STX)
  6. *
  7. *  Modification history:
  8. *
  9. *   V1.0  22-Jan-91, J Love    Original version (for CDF V2.0).
  10. *   V1.1  20-Sep-91, J Love    Modified for IBM-PC port.
  11. *   V1.2  10-Feb-92, J Love    CDF V2.2.
  12. *
  13. ******************************************************************************/
  14.  
  15. #if defined(vms)        /* THIS FILE ONLY USED ON VMS SYSTEMS */
  16.  
  17. #include "cdflib.h"
  18.  
  19. struct attrInfoStruct {
  20. long            attrNum;
  21. long            dataType;
  22. long            numElements;
  23. Boolean            compatible;
  24. struct attrInfoStruct    *next;
  25. };
  26.  
  27. struct CDFinfoStruct {
  28. CDFid            id;
  29. struct attrInfoStruct    *attrHeader;
  30. struct CDFinfoStruct    *next;
  31. };
  32.  
  33. static struct CDFinfoStruct    *CDFheader = NULL;
  34.  
  35.  
  36. /******************************************************************************
  37. *  initializeCDFinfo.
  38. ******************************************************************************/
  39.  
  40. CDFstatus initializeCDFinfo (id)
  41. CDFid    id;
  42. {
  43. struct CDFinfoStruct    *CDFptr;
  44. struct CDFinfoStruct    *CDFtrailer;
  45.  
  46. if (CDFheader == NULL) {
  47.    CDFptr = (struct CDFinfoStruct *) malloc (sizeof(struct CDFinfoStruct));
  48.    if (CDFptr == NULL) return BAD_MALLOC;
  49.  
  50.    CDFptr->id = id;
  51.    CDFptr->attrHeader = NULL;
  52.    CDFptr->next = NULL;
  53.  
  54.    CDFheader = CDFptr;
  55. }
  56. else {
  57.    CDFptr = CDFheader;
  58.  
  59.    while (CDFptr != NULL) {
  60.       if (CDFptr->id == id) {
  61.      freeAttrInfo (CDFptr->attrHeader);
  62.      CDFptr->attrHeader = NULL;
  63.      break;
  64.       }
  65.  
  66.       CDFtrailer = CDFptr;
  67.       CDFptr = CDFptr->next;
  68.    }
  69.  
  70.    if (CDFptr == NULL) {
  71.       CDFptr = (struct CDFinfoStruct *) malloc (sizeof(struct CDFinfoStruct));
  72.       if (CDFptr == NULL) return BAD_MALLOC;
  73.  
  74.       CDFptr->id = id;
  75.       CDFptr->attrHeader = NULL;
  76.       CDFptr->next = NULL;
  77.  
  78.       CDFtrailer->next = CDFptr;
  79.    }
  80. }
  81.  
  82. return inquireCDFinfo (id, CDFptr);
  83. }
  84.  
  85.  
  86. /******************************************************************************
  87. *  inquireCDFinfo.
  88. ******************************************************************************/
  89.  
  90. CDFstatus inquireCDFinfo (id, CDFptr)
  91. CDFid id;
  92. struct CDFinfoStruct *CDFptr;
  93. {
  94. CDFstatus    Status;
  95. long        numDims;
  96. long        dimSizes[CDF_MAX_DIMS];
  97. long        encoding;
  98. long        majority;
  99. long        numRecs;
  100. long        numVars;
  101. long        numAttrs;
  102. long        attrNum;
  103. long        entryNum;
  104. long        dataType;
  105. long        numElements;
  106. long        attrScope;
  107. long        maxEntry;
  108. char        attrName[CDF_ATTR_NAME_LEN+1];
  109.  
  110. Status = CDFinquire (id, &numDims, dimSizes, &encoding, &majority,
  111.              &numRecs, &numVars, &numAttrs);
  112. if (Status < CDF_OK) return Status;
  113.  
  114. for (attrNum = 0; attrNum < numAttrs; attrNum++) {
  115.    Status = CDFattrInquire (id, attrNum, attrName, &attrScope, &maxEntry);
  116.    if (Status < CDF_OK) return Status;
  117.  
  118.    for (entryNum = 0; entryNum <= maxEntry; entryNum++) {
  119.       Status = CDFattrEntryInquire (id, attrNum, entryNum, &dataType,
  120.                     &numElements);
  121.       if (Status == NO_SUCH_ENTRY)
  122.     break;
  123.       else
  124.     if (Status < CDF_OK)
  125.       return Status;
  126.     else {
  127.       Status = putAttrInfo (id, attrNum, dataType, numElements);
  128.       if (Status < CDF_OK) return Status;
  129.       break;
  130.     }
  131.    }
  132. }
  133.  
  134. return CDF_OK;
  135. }
  136.  
  137.  
  138. /******************************************************************************
  139. *  freeAttrInfo.
  140. ******************************************************************************/
  141.  
  142. void freeAttrInfo (attrPtr)
  143. struct attrInfoStruct *attrPtr;
  144. {
  145. struct attrInfoStruct    *nextAttrPtr;
  146.  
  147. while (attrPtr != NULL) {
  148.    nextAttrPtr = attrPtr->next;
  149.    free (attrPtr);
  150.    attrPtr = nextAttrPtr;
  151. }
  152.  
  153. return;
  154. }
  155.  
  156.  
  157. /******************************************************************************
  158. *  putAttrInfo.
  159. ******************************************************************************/
  160.  
  161. CDFstatus putAttrInfo (id, attrNum, dataType, numElements)
  162. CDFid    id;
  163. long    attrNum;
  164. long    dataType;
  165. long    numElements;
  166. {
  167. struct CDFinfoStruct    *CDFptr;
  168. struct attrInfoStruct    *attrPtr;
  169. struct attrInfoStruct    *attrTrailer = NULL;
  170.  
  171. CDFptr = CDFheader;
  172.  
  173. while (CDFptr != NULL) {
  174.    if (CDFptr->id == id) {
  175.       attrPtr = CDFptr->attrHeader;
  176.  
  177.       while (attrPtr != NULL) {
  178.      if (attrPtr->attrNum == attrNum) {
  179.         if (attrPtr->dataType != dataType ||
  180.         attrPtr->numElements != numElements)
  181.            attrPtr->compatible = FALSE;
  182.         return CDF_OK;
  183.      }
  184.  
  185.      attrTrailer = attrPtr;
  186.      attrPtr = attrPtr->next;
  187.       }
  188.  
  189.       attrPtr = (struct attrInfoStruct *)
  190.         malloc (sizeof(struct attrInfoStruct));
  191.       if (attrPtr == NULL) return BAD_MALLOC;
  192.  
  193.       attrPtr->attrNum = attrNum;
  194.       attrPtr->dataType = dataType;
  195.       attrPtr->numElements = numElements;
  196.       attrPtr->compatible = TRUE;
  197.       attrPtr->next = NULL;
  198.  
  199.       if (attrTrailer == NULL)
  200.      CDFptr->attrHeader = attrPtr;
  201.        else
  202.      attrTrailer->next = attrPtr;
  203.  
  204.       return CDF_OK;
  205.    }
  206.  
  207.    CDFptr = CDFptr->next;
  208. }
  209.  
  210. return BAD_CDF_ID;
  211. }
  212.  
  213.  
  214. /******************************************************************************
  215. *  getAttrInfo.
  216. ******************************************************************************/
  217.  
  218. CDFstatus getAttrInfo (id, attrNum, dataType, numElements)
  219. CDFid    id;
  220. long    attrNum;
  221. long    *dataType;
  222. long    *numElements;
  223. {
  224. struct CDFinfoStruct    *CDFptr;
  225. struct attrInfoStruct    *attrPtr;
  226. struct attrInfoStruct    *attrTrailer;
  227.  
  228. CDFptr = CDFheader;
  229.  
  230. while (CDFptr != NULL) {
  231.    if (CDFptr->id == id) {
  232.       attrPtr = CDFptr->attrHeader;
  233.  
  234.       while (attrPtr != NULL) {
  235.      if (attrPtr->attrNum == attrNum)
  236.         if (attrPtr->compatible) {
  237.            *dataType = attrPtr->dataType;
  238.            *numElements = attrPtr->numElements;
  239.            return CDF_OK;
  240.         }
  241.         else
  242.            return CDF_INCOMPATIBLE;
  243.  
  244.      attrPtr = attrPtr->next;
  245.       }
  246.  
  247.       return NO_SUCH_ATTR;
  248.    }
  249.  
  250.    CDFptr = CDFptr->next;
  251. }
  252.  
  253. return BAD_CDF_ID;
  254. }
  255.  
  256. #endif
  257.